using MediatR;
using RBAC.ErrorCode;
using System.ComponentModel.DataAnnotations;

namespace RBAC.Write.Api.Application.Command.ERP.SalesManagement.Billing
{
    /// <summary>
    /// 开票通知单导出命令
    /// 支持单据模式和明细模式两种导出方式
    /// </summary>
    public class ExportBillingNoticeCommand : IRequest<APIResult<byte[]>>
    {
        /// <summary>
        /// 单据编号（模糊查询）
        /// </summary>
        public string? BillNo { get; set; }

        /// <summary>
        /// 客户名称（模糊查询）
        /// </summary>
        public string? CustomerName { get; set; }

        /// <summary>
        /// 开票名称（模糊查询）
        /// </summary>
        public string? InvoiceName { get; set; }

        /// <summary>
        /// 开始日期
        /// </summary>
        public DateTime? StartDate { get; set; }

        /// <summary>
        /// 结束日期
        /// </summary>
        public DateTime? EndDate { get; set; }

        /// <summary>
        /// 导出类型：1-单据模式，2-明细模式
        /// </summary>
        [Range(1, 2)]
        public int ExportType { get; set; } = 1;

        /// <summary>
        /// 是否导出全部数据（不分页）
        /// </summary>
        public bool ExportAll { get; set; } = false;

        /// <summary>
        /// 页码（仅当ExportAll=false时有效）
        /// </summary>
        [Range(1, int.MaxValue)]
        public int PageIndex { get; set; } = 1;

        /// <summary>
        /// 每页条数（仅当ExportAll=false时有效）
        /// </summary>
        [Range(1, 10000)]
        public int PageSize { get; set; } = 1000;
    }

    /// <summary>
    /// 开票通知单导出DTO（单据模式）
    /// </summary>
    public class BillingNoticeExportDto
    {
        /// <summary>
        /// 单据编号
        /// </summary>
        public string? BillNumber { get; set; }

        /// <summary>
        /// 业务类型
        /// </summary>
        public string? BusinessType { get; set; }

        /// <summary>
        /// 客户名称
        /// </summary>
        public string? CustomerName { get; set; }

        /// <summary>
        /// 开户行
        /// </summary>
        public string? BankName { get; set; }

        /// <summary>
        /// 交付邮箱
        /// </summary>
        public string? DeliveryEmail { get; set; }

        /// <summary>
        /// 单据日期
        /// </summary>
        public DateTime? BillDate { get; set; }

        /// <summary>
        /// 操作员
        /// </summary>
        public string? Operator { get; set; }

        /// <summary>
        /// 蓝单红字（发票类型）
        /// </summary>
        public string? InvoiceType { get; set; }

        /// <summary>
        /// 银行账号
        /// </summary>
        public string? ProductCode { get; set; }

        /// <summary>
        /// 红字原因
        /// </summary>
        public string? RedReason { get; set; }

        /// <summary>
        /// 备注信息
        /// </summary>
        public string? Remarks { get; set; }

        /// <summary>
        /// 单据状态（中文：开立、审核、退回）
        /// </summary>
        public string? BillStatus { get; set; }

        /// <summary>
        /// 审批员
        /// </summary>
        public string? Reviewer { get; set; }

        /// <summary>
        /// 税率
        /// </summary>
        public decimal? TaxRate { get; set; }

        /// <summary>
        /// 税号
        /// </summary>
        public string? TaxId { get; set; }

        /// <summary>
        /// 业务状态
        /// </summary>
        public string? BusinessStatus { get; set; }

        /// <summary>
        /// 审批日期
        /// </summary>
        public DateTime? ReviewDate { get; set; }

        /// <summary>
        /// 发票类型
        /// </summary>
        public string? InvoiceCategory { get; set; }

        /// <summary>
        /// 地址电话
        /// </summary>
        public string? AddressPhone { get; set; }

        /// <summary>
        /// 合计金额
        /// </summary>
        public decimal TotalAmount { get; set; }
    }

    /// <summary>
    /// 开票明细导出DTO（明细模式）
    /// </summary>
    public class BillingDetailExportDto
    {
        /// <summary>
        /// 单据编号
        /// </summary>
        public string? BillNumber { get; set; }

        /// <summary>
        /// 客户名称
        /// </summary>
        public string? CustomerName { get; set; }

        /// <summary>
        /// 单据日期
        /// </summary>
        public DateTime? BillDate { get; set; }

        /// <summary>
        /// 销售订单号
        /// </summary>
        public string? OrderNumber { get; set; }

        /// <summary>
        /// 物料编码
        /// </summary>
        public string? MaterialCode { get; set; }

        /// <summary>
        /// 物料名称
        /// </summary>
        public string? MaterialName { get; set; }

        /// <summary>
        /// 规格型号
        /// </summary>
        public string? Specification { get; set; }

        /// <summary>
        /// 主计量单位
        /// </summary>
        public string? Unit { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        public int? Quantity { get; set; }

        /// <summary>
        /// 单价
        /// </summary>
        public decimal? UnitPrice { get; set; }

        /// <summary>
        /// 金额
        /// </summary>
        public decimal? Amount { get; set; }

        /// <summary>
        /// 开票名称
        /// </summary>
        public string? InvoiceName { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remarks { get; set; }

        /// <summary>
        /// 单据状态（中文：开立、审核、退回）
        /// </summary>
        public string? BillStatus { get; set; }
    }
}